package com.tf_cut.admin;

import org.springframework.context.annotation.Configuration;

import com.netflix.hystrix.exception.HystrixBadRequestException;

import feign.Response;

/**
 * 防范内部业务异常，出发服务熔断
 * @author Administrator
 *
 */
@Configuration
public class BizExceptionFeignErrorDecoder implements feign.codec.ErrorDecoder{

    @Override
    public Exception decode(String methodKey, Response response) {
        if(response.status() >= 400 && response.status() <= 499){
            return new HystrixBadRequestException("request exception wrapper："+response.status());
        }
        return feign.FeignException.errorStatus(methodKey, response);
    }
}